﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace Nizm0.QOT.Library.Objects
{
    [Serializable]
    public class RegexPatern : ISerializable 
    {
        public string Pattern
        {
            get;
            set;
        }

        public string Group
        {
            get;
            set;
        }

        public RegexPatern(string group, string pattern)
        {
            this.Group = group;
            this.Pattern = pattern;
        }
        public RegexPatern(SerializationInfo info, StreamingContext ctxt)
        {
            Group = (string)info.GetValue("Group", typeof(string));
            Pattern = (String)info.GetValue("Pattern", typeof(string));
        }
        public RegexPatern()
        { }

        public override string ToString()
        {
            return Pattern;
        }

        public Stream Serialize()
        {
            //string serialString = null;
            using (System.IO.MemoryStream ms1 = new System.IO.MemoryStream())
            {
                BinaryFormatter b = new BinaryFormatter();
                b.Serialize(ms1, Settings.Instance);//Settings.Instance
                //byte[] arrayByte = ms1.ToArray();
                //serialString = Convert.ToBase64String(arrayByte);
                return ms1;
            }
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Group", Group);
            info.AddValue("Pattern", Pattern);
        }
    }
}
